Repository navigation
Harden RootLock against planted lock files - #4
Merged
Merged
Conversation
acquire opened STATE_ROOT/.lock by path, took the flock and truncated it without looking at the descriptor, so a hard link planted at that name lost the other name's bytes, and a FIFO there was opened and locked; a symbolic link used as the state root was followed. The state root is now opened O_DIRECTORY|O_NOFOLLOW and both lock files relative to it with O_NOFOLLOW, created mode 0600. A name that is not absent or a regular file with one link is refused before the open, the descriptor is checked after it, and the gate is checked again after the locks are taken, right before the truncate: still a regular file with one link, still the one at .lock, so unlinking the planted name during the wait does not pass. A refused gate is GateNotPrivate; LockOps.open_sidecar takes the state root's descriptor and a name.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RootLock.acquiretruncated.lockand wrote the pid without checking what the name pointed at. A hard link, symlink or FIFO planted at either lock name, or a symlinked state root, let it overwrite or block on a file outside the state root.Now
acquire:O_DIRECTORY|O_NOFOLLOWand strips trailing slashes, since a trailing slash makes the kernel follow a symlink;O_NOFOLLOW|O_NONBLOCK, created mode 0600;.lockstill has one link and the same device and inode as the descriptor.A refused
.lockraises the newAcquireError.GateNotPrivate. A symlinked root raisesNotDir.LockOps.open_sidecarnow takes the directory descriptor and a name. Theacquiresignature is unchanged.Six new tests cover hard links (planted before and during the wait), a gate renamed during the wait, a FIFO at either name, symlinks and the 0600 mode; all fail on main.
zig build testpasses. eb-staged-rebuild, the only caller, builds and passes its tests against this branch.Not covered: symlinks in parent directories of the state root, and existing 0644 lock files keep their mode.
mainhas no towncrier, so the entry is inCHANGELOG.mdunder Unreleased. This conflicts withfix/safety; whichever lands second needs a rebase.